#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "mini.kit/text.h"
#include "mini.kit/socket.h"

int main(int argc, char* argv[])
{
	const char* host = NULL;
	int32_t     port = 0;
	if( argc < 3 ) {
		fprintf(stderr, "usage: %s host port\n", argv[0]);
		return 1;
	}
	host = argv[1];
	port = atoi( argv[2] );
	try{
		for( size_t i=0; i<10; i++)
		{
			MINIKIT::TCPClientSocket client;
			client.connect( host, port );
			std::string str_send;
			MINIKIT::Text::sprintf( str_send, "oh~my~[%u]~~", i );
			char buff[256]={0};
			client.send( str_send.c_str(), str_send.size() );
			client.recv( buff, 256 );
			fprintf( stdout, "[%s:%d -> %s:%d] got echo-recv:{%s}\n"
				, client.getLocalAddr().c_str(), client.getLocalPort()
				, client.getRemoteAddr().c_str(), client.getRemotePort()
				, buff 
			);
			client.close();
		}
	}
	catch(MINIKIT::SocketException& ex)
	{
		fprintf(stderr, "err: %s\n", ex.what());
	}
	
	return 0;
}

